class ListNode(object):
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next


class Solution(object):
    def deleteNodes(self, head, m, n):
        mute_node = ListNode(0, head)
        node = head
        state = 0
        index = 0
        prev = mute_node
        while node:
            if state == 0:
                index += 1
                prev = node
                node = node.next
                if index == m:
                    index = 0
                    state = 1
            else:
                index += 1
                prev.next = node.next
                node = node.next
                if index == n:
                    index = 0
                    state = 0
        return mute_node.next

